var stop = false;
function getValidateCode(type) {
  if(type == 1){
    if(!$("#email").valid() | !$("#passwordConfirm").valid()
      | !$("#password").valid() | !$("#userName").valid()){
      return false;
    }
  }else{
    if(!$("#email").valid()){
      return false;
    }
  }
  stop = true;
  var condition = {
    "email" : $("#email").val(),
    "type" : type,
    "userName" : $("#userName").val()

  };
  if(stop){
    $.ajax({
      url : "sendEmail",
      data : JSON.stringify(condition),
      contentType: "application/json",
      dataType : 'json',
      type : "post",
      success : function(data) {
        if(data.code==200){
          $("#errorPlace").html(data.msg);
          countdowm();
        } else {
          $("#errorPlace").html(data.msg);
        }
      }
    });
  }
}

function countdowm(){
  stop = false;
  $("#countdowm_button").attr("disabled","disabled");
  var i = 60;
  var seelp = setInterval(function(){
    if(i>0){
      $("#countdowm_button").html(i--);
    }else{
      window.clearInterval(seelp);
      $("#countdowm_button").html("发送验证码");
      $("#countdowm_button").removeAttr("disabled");
    }
  },1000);
}

function changePic(){
  var timestamp = (new Date()).valueOf();
  var url = "getValidCodeImage?time="+timestamp;
  $("#picCode").attr("src",url);
  $("#picCodeInput").val("");
}
function refresh(){
    document.getElementById("picCode").src = 'getValidCodeImage?t='+new Date().getTime();
}

// JavaScript Document
var setLoginHeight;
var setCheck;

$(function() {
  setLoginHeight = function(){
    var wth = $(window).height();
    var min_th = 600;
    var th = wth > min_th ? wth : min_th;
    $(".loginDiv").height(th);
  };

  setCheck = function(){
    if($(".blue_check").length == 0) return;
    $(".blue_check").iCheck({
      checkboxClass: 'icheckbox_minimal-blue',
      radioClass: 'iradio_minimal-blue',
      increaseArea: '20%' // optional
    });
  };
  setCheck();

  $('.allSelect').dropkick();

})

$(window).resize(function() {
  setLoginHeight();
});
